﻿using System;
using System.Linq;
using System.Net;
using Battle.Net.Infrastructure;
using Battle.Net.Model;

namespace Battle.Net
{
    public class BattleNetException : WebException
    {
        internal BattleNetException(BattleNetError error, WebException webEx)
            : base(webEx.Message, webEx)
        {
            Reason = error.Reason;
            Args = error.Args;
            Request = error.Request;

            var reasons = Enum.GetValues(typeof (ErrorReasons)).AsQueryable().Cast<ErrorReasons>();
            ErrorType = reasons.SingleOrDefault(r => r.ToEnumString() == error.Reason);
        }

        public override string Message
        {
            get { return Reason; }
        }

        public ErrorReasons ErrorType { get; set; }

        public string Reason { get; set; }

        public object[] Args { get; set; }

        public string Request { get; set; }
    }

}
